<template>
    <div>
        <common-header></common-header>
        <common-title></common-title>
        <add-set @getCinfo="handleGetCinfo"></add-set>
        <hr>
        <add-list @pageChange="handlePageChange" :totalPages="totalPages" :list="list" :totalData="totalData"></add-list>
    </div>
</template>

<script>
import axios from 'axios'
import { mapState } from 'Vuex'
import CommonHeader from 'common/components/header'
import CommonTitle from 'common/components/title'
import AddSet from './components/set'
import AddList from './components/list'
export default {
  name: 'add',
  data () {
    return {
      show: false,
      show1: false,
      list: [],
      totalData: '',
      curPage: '1',
      totalPages: ''
    }
  },
  components: {
    CommonHeader,
    CommonTitle,
    AddSet,
    AddList
  },
  methods: {
    handlePageChange (curPage) {
      this.curPage = curPage
      this.getAdminInfo()
    },
    handleGetCinfo () {
      this.getAdminInfo()
    },
    getAdminInfo () {
      // console.log(this.userId)
      // console.log(this.curPage.toString())
      axios.post('http://192.168.43.188:8081/getVoteVoters', {
        'id': this.userId,
        'pn': this.curPage.toString()
      }).then(({status, data}) => {
        // console.log(data)
        if (data && data.msg === '111') {
          this.totalPages = data.tp.toString()
          this.totalData = data.td.toString()
          this.list = data.info
        } else if (data.msg) {}
      }).catch((error) => {
        swal( 'Info' + error, '', 'error')
      })
    },
    back () {
      if (!this.userPassword) {
        swal("请重新登录输入密码", '', 'warning')
        this.$router.push('/')
      }
    }
  },
  computed: {
    ...mapState(['userPassword']),
    ...mapState(['userId']),
    ...mapState(['vStatus'])
  },
  mounted () {
    this.back()
    if (this.vStatus) {
      console.log(this.vStatus)
      this.getAdminInfo ()
    }
  }
}
</script>

<style lang="stylus" scoped>
@import '~style/variable.styl'
// .hr
//     border: .02rem solid #666
//     color: #666
</style>
